home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / GrowingImage / GrowingImage.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  9.0 KB  |  402 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Cursor;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.MediaTracker;
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.MouseListener;
  13. import java.net.MalformedURLException;
  14. import java.net.URL;
  15. import java.net.URLEncoder;
  16.  
  17. public class GrowingImage extends Applet implements Runnable, MouseListener {
  18.    private Thread thread;
  19.    private Image image;
  20.    private Image buffer;
  21.    private Image backImage;
  22.    // $FF: renamed from: b java.awt.Graphics
  23.    private Graphics field_0;
  24.    private boolean loaded;
  25.    // $FF: renamed from: wi int
  26.    private int field_1;
  27.    // $FF: renamed from: he int
  28.    private int field_2;
  29.    private int wiIm;
  30.    private int heIm;
  31.    private int pause = 100;
  32.    private int decx;
  33.    private int decy;
  34.    private int decxBack;
  35.    private int decyBack;
  36.    // $FF: renamed from: X float
  37.    private float field_3;
  38.    // $FF: renamed from: Y float
  39.    private float field_4;
  40.    private String statusBarText;
  41.    private AudioClip sound;
  42.    private AudioClip clicSound;
  43.    private AudioClip enterSound;
  44.    private boolean loopSound;
  45.    private String link;
  46.    // $FF: renamed from: fm java.awt.FontMetrics
  47.    private FontMetrics field_5;
  48.    private String enterText;
  49.    private boolean isEnterTextEnabled;
  50.    private int wiEnterText;
  51.    private int enterTextHeight;
  52.    private Color enterTextColor;
  53.  
  54.    public String getAppletInfo() {
  55.       return "Name: GrowingImage\r\nAuthor: Taiji Software\r\n";
  56.    }
  57.  
  58.    public GrowingImage() {
  59.       ((Component)this).addMouseListener(this);
  60.    }
  61.  
  62.    public void register() {
  63.       try {
  64.          URL u = new URL("http://www.taijisoftware.com");
  65.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  66.       } catch (Exception e) {
  67.          System.out.println(e);
  68.          this.stop();
  69.       }
  70.    }
  71.  
  72.    public void init() {
  73.       String codeBase = null;
  74.  
  75.       try {
  76.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  77.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  78.          codeBase = codeBase.toUpperCase();
  79.       } catch (Exception var9) {
  80.       }
  81.  
  82.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  83.          String regCode = ((Applet)this).getParameter("registration_code");
  84.          if (regCode == null) {
  85.             regCode = ((Applet)this).getParameter("reg_domain");
  86.             if (regCode == null) {
  87.                this.register();
  88.             } else {
  89.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  90.                   codeBase = "WWW." + codeBase;
  91.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  92.                   codeBase = codeBase.substring(4);
  93.                }
  94.  
  95.                char[] chars = new char[codeBase.length()];
  96.                codeBase.getChars(0, codeBase.length(), chars, 0);
  97.                String key = new String("haricot");
  98.                char[] chars2 = new char[key.length()];
  99.                key.getChars(0, key.length(), chars2, 0);
  100.  
  101.                for(int i = 0; i < codeBase.length(); ++i) {
  102.                   int j;
  103.                   if (i >= key.length()) {
  104.                      j = i - key.length() * (i / key.length());
  105.                   } else {
  106.                      j = i;
  107.                   }
  108.  
  109.                   chars[i] += chars2[j];
  110.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  111.                }
  112.  
  113.                String res = new String(chars);
  114.                if (!res.equalsIgnoreCase(regCode)) {
  115.                   this.register();
  116.                }
  117.             }
  118.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  119.             this.register();
  120.          }
  121.       }
  122.  
  123.       this.getParameters();
  124.       if (this.sound != null) {
  125.          if (this.loopSound) {
  126.             this.sound.loop();
  127.             return;
  128.          }
  129.  
  130.          this.sound.play();
  131.       }
  132.  
  133.    }
  134.  
  135.    public void getParameters() {
  136.       this.field_1 = ((Component)this).getSize().width;
  137.       this.field_2 = ((Component)this).getSize().height;
  138.       String s = ((Applet)this).getParameter("pause");
  139.       if (s != null) {
  140.          this.pause = Integer.parseInt(s);
  141.       }
  142.  
  143.       ((Component)this).setBackground(this.getColor("background_color"));
  144.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  145.       s = ((Applet)this).getParameter("sound_name");
  146.       if (s != null) {
  147.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  148.       }
  149.  
  150.       s = ((Applet)this).getParameter("loop_sound");
  151.       if (s != null) {
  152.          if (s.equals("yes")) {
  153.             this.loopSound = true;
  154.          } else {
  155.             this.loopSound = false;
  156.          }
  157.       }
  158.  
  159.       s = ((Applet)this).getParameter("clic_sound_name");
  160.       if (s != null) {
  161.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  162.       }
  163.  
  164.       s = ((Applet)this).getParameter("enter_sound_name");
  165.       if (s != null) {
  166.          this.enterSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  167.       }
  168.  
  169.       this.link = ((Applet)this).getParameter("link");
  170.       this.enterText = ((Applet)this).getParameter("enter_text");
  171.       s = ((Applet)this).getParameter("enter_text_height");
  172.       if (s != null) {
  173.          this.enterTextHeight = Integer.parseInt(s);
  174.       }
  175.  
  176.       this.enterTextColor = this.getColor("enter_text_color");
  177.       if (this.enterTextColor == null) {
  178.          this.enterTextColor = Color.white;
  179.       }
  180.  
  181.    }
  182.  
  183.    public Color getColor(String param) {
  184.       String s = ((Applet)this).getParameter(param);
  185.       if (s != null) {
  186.          if (s.substring(0, 1).equals("#")) {
  187.             s = s.substring(1);
  188.             int i = Integer.parseInt(s, 16);
  189.             return new Color(i);
  190.          } else {
  191.             return null;
  192.          }
  193.       } else {
  194.          return null;
  195.       }
  196.    }
  197.  
  198.    public void paint(Graphics g) {
  199.       if (this.loaded) {
  200.          this.field_0.clearRect(0, 0, this.field_1, this.field_2);
  201.          if (this.backImage != null) {
  202.             this.field_0.drawImage(this.backImage, this.decxBack, this.decyBack, this);
  203.          }
  204.  
  205.          this.field_0.drawImage(this.image, this.decx + this.wiIm - (int)this.field_3, this.decy + this.heIm - (int)this.field_4, this.decx + (int)this.field_3, this.decy + (int)this.field_4, this.wiIm - (int)this.field_3, this.heIm - (int)this.field_4, (int)this.field_3, (int)this.field_4, this);
  206.          if (this.isEnterTextEnabled) {
  207.             this.field_0.drawString(this.enterText, (this.field_1 - this.wiEnterText) / 2, this.field_2 / 2);
  208.          }
  209.  
  210.          g.drawImage(this.buffer, 0, 0, this);
  211.       }
  212.  
  213.    }
  214.  
  215.    public void update(Graphics g) {
  216.       this.paint(g);
  217.    }
  218.  
  219.    public void start() {
  220.       if (this.thread == null) {
  221.          this.thread = new Thread(this);
  222.          this.thread.start();
  223.       }
  224.  
  225.    }
  226.  
  227.    public void stop() {
  228.       if (this.thread != null) {
  229.          this.thread = null;
  230.       }
  231.  
  232.       if (this.sound != null) {
  233.          this.sound.stop();
  234.       }
  235.  
  236.    }
  237.  
  238.    public void run() {
  239.       if (!this.loaded) {
  240.          MediaTracker tracker = new MediaTracker(this);
  241.          this.image = ((Applet)this).getImage(((Applet)this).getCodeBase(), ((Applet)this).getParameter("image"));
  242.          tracker.addImage(this.image, 0);
  243.          if (((Applet)this).getParameter("background_image") != null) {
  244.             this.backImage = ((Applet)this).getImage(((Applet)this).getCodeBase(), ((Applet)this).getParameter("background_image"));
  245.             tracker.addImage(this.backImage, 0);
  246.          }
  247.  
  248.          try {
  249.             tracker.waitForAll();
  250.             this.loaded = !tracker.isErrorAny();
  251.          } catch (Exception e) {
  252.             System.out.println(e);
  253.          }
  254.  
  255.          if (!this.loaded) {
  256.             this.stop();
  257.          }
  258.       }
  259.  
  260.       this.wiIm = this.image.getWidth(this);
  261.       this.heIm = this.image.getHeight(this);
  262.       this.decx = (this.field_1 - this.wiIm) / 2;
  263.       this.decy = (this.field_2 - this.heIm) / 2;
  264.       if (this.backImage != null) {
  265.          this.decxBack = (this.field_1 - this.backImage.getWidth(this)) / 2;
  266.          this.decyBack = (this.field_2 - this.backImage.getHeight(this)) / 2;
  267.       }
  268.  
  269.       this.buffer = ((Component)this).createImage(this.field_1, this.field_2);
  270.       this.field_0 = this.buffer.getGraphics();
  271.       this.field_0.setColor(this.enterTextColor);
  272.       String fontName = ((Applet)this).getParameter("enter_text_font");
  273.       if (fontName == null) {
  274.          fontName = "TimesRoman";
  275.       }
  276.  
  277.       int style = 1;
  278.       String s = ((Applet)this).getParameter("enter_text_style");
  279.       if (s != null) {
  280.          if (s.equals("bold")) {
  281.             style = 1;
  282.          } else if (s.equals("italic")) {
  283.             style = 2;
  284.          } else if (s.equals("bold_italic")) {
  285.             style = 3;
  286.          } else {
  287.             style = 0;
  288.          }
  289.       }
  290.  
  291.       this.field_0.setFont(new Font(fontName, style, this.enterTextHeight));
  292.       this.field_5 = this.field_0.getFontMetrics();
  293.       if (this.enterText != null) {
  294.          this.wiEnterText = this.field_5.stringWidth(this.enterText);
  295.       }
  296.  
  297.       this.field_3 = (float)(this.wiIm / 2);
  298.       this.field_4 = (float)(this.heIm / 2);
  299.       float rap = (float)this.heIm / (float)this.wiIm;
  300.  
  301.       while(true) {
  302.          ((Component)this).repaint();
  303.          ++this.field_3;
  304.          this.field_4 += rap;
  305.          if (this.field_3 > (float)(this.wiIm - 1)) {
  306.             return;
  307.          }
  308.  
  309.          if (this.field_4 > (float)this.heIm) {
  310.             this.field_4 = (float)this.heIm;
  311.          }
  312.  
  313.          try {
  314.             Thread.sleep((long)this.pause);
  315.          } catch (InterruptedException var5) {
  316.             this.stop();
  317.          }
  318.       }
  319.    }
  320.  
  321.    public URL giveURL(String url) {
  322.       try {
  323.          if (url.toUpperCase().startsWith("HTTP")) {
  324.             return new URL(url);
  325.          } else if (url.toUpperCase().startsWith("FTP")) {
  326.             int p = url.indexOf(":");
  327.             int p2 = url.indexOf(":", p + 1);
  328.             if (p2 != -1) {
  329.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  330.             }
  331.  
  332.             p = url.indexOf("%40");
  333.             if (p != -1) {
  334.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  335.             }
  336.  
  337.             return new URL(url);
  338.          } else {
  339.             return new URL(((Applet)this).getCodeBase(), url);
  340.          }
  341.       } catch (MalformedURLException e) {
  342.          System.out.println(e);
  343.          return null;
  344.       }
  345.    }
  346.  
  347.    public void mouseClicked(MouseEvent e) {
  348.    }
  349.  
  350.    public void mouseEntered(MouseEvent e) {
  351.       if (this.enterText != null) {
  352.          this.isEnterTextEnabled = true;
  353.          ((Component)this).repaint();
  354.       }
  355.  
  356.       if (this.statusBarText != null) {
  357.          ((Applet)this).showStatus(this.statusBarText);
  358.       }
  359.  
  360.       if (this.enterSound != null) {
  361.          this.enterSound.play();
  362.       }
  363.  
  364.       if (this.link != null) {
  365.          ((Component)this).setCursor(new Cursor(12));
  366.       }
  367.  
  368.    }
  369.  
  370.    public void mouseExited(MouseEvent e) {
  371.       if (this.isEnterTextEnabled) {
  372.          this.isEnterTextEnabled = false;
  373.          ((Component)this).repaint();
  374.       }
  375.  
  376.       if (this.link != null) {
  377.          ((Component)this).setCursor(new Cursor(0));
  378.       }
  379.  
  380.    }
  381.  
  382.    public void mousePressed(MouseEvent e) {
  383.       if (this.clicSound != null) {
  384.          this.clicSound.play();
  385.       }
  386.  
  387.       if (this.link != null) {
  388.          String target = ((Applet)this).getParameter("target");
  389.          if (target == null) {
  390.             target = "_blank";
  391.          }
  392.  
  393.          URL u = this.giveURL(this.link);
  394.          ((Applet)this).getAppletContext().showDocument(u, target);
  395.       }
  396.  
  397.    }
  398.  
  399.    public void mouseReleased(MouseEvent e) {
  400.    }
  401. }
  402.